package com.gmail.liulijuan;

public class SorterChar {
	
	char[] c;
	
	private void setC(char[] a){
		c=new char[a.length];
		for (int i = 0; i < c.length; i++) {
			c[i]=a[i];
		}
	}
	
	public char[] sortChaRu(int t){
		char b;
		if (t==0) {
			for (int i = 0; i < c.length; i++) {
				for (int j = 0; j < i; j++) {
					if (c[i]>c[j]) {
						b=c[i];
						c[i]=c[j];
						c[j]=b;
					}
				}
			}
		} else {
			for (int m = 0; m < c.length; m++) {
				for (int n = 0; n < m; n++) {
					if (c[m]<c[n]) {
						b=c[m];
						c[m]=c[n];
						c[n]=b;
					}
				}
			}
		}
		return c;
	}
	
	public char[] sortMaoPao(int t){
		char b;
		for (int i = 1; i < c.length; i++) {
			for (int j = 0; j < c.length-i; j++) {
				if (c[j+1]>c[j]) {
					b=c[j];
					c[j]=c[j+1];
					c[j+1]=b;
				}	
			}
		}
		if(t>0){
			return reverse(c);
		}
		return c;
	}
		
	public char[] sortShunXu(int t){
		char b;
		for (int i = 0; i < c.length; i++) {
			for (int j = i; j < c.length; j++) {
				if (c[i] < c[j]) {
					b = c[i];
					c[i] = c[j];
					c[j] = b;
				}
			}
		}
		if(t>0){
			return reverse(c);
		}
		return c;
	}
	
	private char[] reverse(char[]a){
		char[] b=new char[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=a[a.length-i-1];
		}
		return b;
	}

	public SorterChar(char[] a){
		setC(a);
		
	}
}
